window.onload=function(){
	listComment("");
	$POSMENU=6;
	new CHECKLOGIN().check();
	
}
function viewById(){
	var id = $N("id")[0].value;
	listComment(id);
}

COMMENT = function(){}
COMMENT.prototype.listComment=function(id){
	var fncSce = XHR.Delegate(this,this.listCommentSce);
	var param = {action:"listComment",newsid:id}
	var req = new XHR("post",fncSce);
	req.send($PN+"/DoAdmin",param);	
}
COMMENT.prototype.listCommentSce=function(r){
	var xml = r.xml;
	if(getRV(xml)){
		var cm = xml.getElementsByTagName("cm");
		var totaladd=0,html="",htmlline="";
		for(var i=0; i<cm.length; i++){
			html += "<table width=\"800\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"tablecomment\">"+
			          "<tr>"+
			            "<td width=\"60\" align=\"left\" valign=\"top\" style=\"padding-top:2px\">" +
			            "<a href=\"http://rolo.vn/p/view.html?uid="+cm[i].getAttribute("pic")+"\" target=\"_blank\"><img border=\"0\" src=\""+makeUserPic(cm[i].getAttribute("pic"))+"\" width=\"52\" style=\"padding-bottom:10px\"></a></td>"+
			            "<td align=\"left\" valign=\"top\" style=\"padding-bottom:10px\">"+
						"<div><a href=\"http://rolo.vn/p/view.html?uid="+cm[i].getAttribute("pic")+"\" target=\"_blank\" style=\"color:#990000;font-weight:bold\">"+cm[i].getAttribute("name")+"</a> (gửi lúc "+cm[i].getAttribute("time")+") </div>"+
						"<div style=\"margin-top:0px;font-size:12px\">" +
						procEmotion(cm[i].getAttribute("content"))+
						"</div>			" +
						"<div style=\"color:#999\"><span style=\"cursor:pointer\" onClick=\"deleteComment('"+cm[i].getAttribute("id")+"');\">[Xóa]</span>&nbsp;&nbsp;&nbsp;&nbsp;" +
						"<span>Id bài viết: "+cm[i].getAttribute("itemid")+"</span>"+
						"</div>" +
						"</td>"+
			          "</tr>"+
			        "</table>"
		}
		if(html=="") html = "<div style=\"font-weight:bold\" align=\"center\">Chưa có ý kiến nào cả!</div>";
		$("commentlist").innerHTML = html;
	}else{
		
	}
}
COMMENT.prototype.deleteComment=function(id){
	var fncSce = XHR.Delegate(this,this.deleteCommentSce);
	var param = {action:"deleteComment",id:id}
	var req = new XHR("post",fncSce);
	req.send($PN+"/DoAdmin",param);	
}
COMMENT.prototype.deleteCommentSce=function(r){
	var xml = r.xml;
	if(getRV(xml)){
		viewById();
	}

}
function listComment(id){
	new COMMENT().listComment(id);
}
function deleteComment(id){
	if(confirm("Xóa comment? ")){
		new COMMENT().deleteComment(id);
	}
}
var $EMO = [
["*.*","1.png","In love"],
[":>","2.png","I like it"],
[";ss","9.png","Falling the tears"],
["(blush)","10.png","Blushing"],
["@:@","14.png","Angry"],
["@^@","17.png","Dizzy"],
["(y)","20.png","Thumb up"],
[">o<","21.png","Fear"],
[":D","33.png","Laugh"],
["(fun)","42.png","Funny"],
[";(","3.png","Cry"],
[":|","4.png","Do not like"],
[":((","6.png","Tired"],
[":(","5.png","Sad"],
[":)","7.png","Smile"],
["(upset)","8.png","Disapointed"],
["*;*","11.png","Wao"],
["8-)","12.png","Cool"],
[">*<","13.png","Kiss"],
["s:s","15.png","Tomboy 1"],
["^s^","16.png","Kitty"],
["-:-","18.png","Tomboy 2"],
[">.<","19.png","Hurry up"],
["(happy)","22.png","Do not worry"],
["(devil)","23.png","Devil"],
[".;.","24.png","Crave"],
[":p","25.png","Jerk"],
["(eyes)","26.png","Sock"],
["^;^","27.png","I want more"],
["(-)","28.png","Sleep"],
["(angel)","29.png","Angel"],
["(music)","30.png","Singing"],
["-^-","31.png","Unexpected"],
["(sweat)","32.png","Sweat"],
["(sorry)","34.png","Sorry"],
["(please)","35.png","Please"],
["|-(","36.png","Uncomfortable"],
[":O","37.png","Surprised"],
["s@s","38.png","I will kill you"],
["*D*","39.png","Admired"],
["(shy)","40.png","Shy"],
["@;@","41.png","So hot"],
["*P*","43.png","Ble ble"],
["(santa)","44.png","Santa"],
[";)","45.png","Wink"],
["(snowman)","46.png","Snow man"]
];

function procEmotion(text){
 for (var i=0; i< $EMO.length; i++) {
  var t = XMLescape($EMO[i][0]);
  var img='<img src="images/emotion/s/'+$EMO[i][1]+'" title="'+$EMO[i][2]+'" height="21" style="margin-bottom: -3px;"/>';
  while (text.indexOf(t) >= 0) text = text.replace(t, img);
  }
  return text;
}
var $FOCUSTXT="content_cm_1";
function genEmoticon(){
	var html = "";
	for(var i=0; i < $EMO.length;i++){
		html +="<div style=\"float:left;padding-right:5px\"><img onclick=\"addEmotion('"+$EMO[i][0]+"')\" style=\"cursor:pointer\"  title=\""+$EMO[i][2]+"\"  src=\"images/emotion/s/"+$EMO[i][1]+"\"></div>";
	}
	$("emoticonlist").innerHTML = html;
}
function XMLescape(t){
 t=t.replace(/&/g,"&amp;");
    t=t.replace(/</g,"&lt;");
    t=t.replace(/>/g,"&gt;");
    t=t.replace(/\"/g,"&quot;");
    return t;
}
function makeUserPic(pic){
	if(pic==null||pic==""||pic=="null")
		return "imgs/defaultuser.jpg";
	else 
		return "http://account.rolo.vn/accounts/ProfilePicture?"+pic+"=thumb";
}